<?php 
	include "header.html";
	include "mensaje.php";
?>
<script type="text/javascript" src="framework/js/util.js"></script>
<script type="text/javascript" src="framework/js/DB.js"></script>
<!--link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css"/-->
<script src="js/table/jquery.dataTables.min.js"></script>
 <link rel="stylesheet" href="css/themes/base/jquery.ui.accordion.css" />
<script src="js/jquery-ui/jquery.ui.datepicker.min.js"></script>
<script type="text/javascript" src="js/jquery-ui/jquery.ui.dialog.min.js"></script>  
<script>
var maquinas;
var estados;
var tipos;

$(document).ready(function(){
	jQuery.ajaxSetup({async:false});
	armaTablaMatriceria();
  	maquinas=makeCombo("elementoDiv","maquina","maquina","descripcion","");
  	estados=makeCombo("containerEstado","item_estado","matriceria_item_estado","descripcion","");
  	tipos=makeCombo("containerTipo","item_tipo","matriceria_item_tipo","descripcion","generaNumeroItem");
});
function cerrarPopUp(){
	cancelarPregunta();
}
function verPopupMatriceria(id){
	armaVista(id);
	$.blockUI({ 
        message: $('#popUp'),
        overlayCSS: {cursor:'auto'},	
    	   css: {cursor:'auto',
        	     width:'600px',
        	     height:'auto',
        	     top:'10%',
        	     left:'20%',
        	     background:'#DCE5EA'}	
    }); 
	
}

function armaTablaMatriceria(){
	var ret;
	var params={};	
	maquinas=loadMap("maquina",params,"descripcion");
	params["baja"]=0;
	params["numero"]=["LT",9999];
	items=load("matriceria",params);

	var str="<table id='matricerias'><thead><th>Numero</th><th>Maquina</th><th>Opciones</th></thead><tbody>";
	for (x=0;x<items.rowCount;x++){
		var obj=items.rows[x];		
		str += "<tr><td>" + obj.numero + "</td><td>" + maquinas[obj.idMaquina] + "</td><td><a href='detalleMatriceria.php?id=" + obj.id + "'>Detalle</a> &nbsp; | <a href='editarMatriceria.php?id=" + obj.id + "'>Editar</a> &nbsp;| <a href='registroControlMatriceria.php?idMatriceria=" + obj.id + "'>Control</a> | &nbsp;  <a href='javascript:borrarMatriceria(" + obj.id + ")'>Borrar</a></td></tr>";
	}			
	str+="</tbody></table>";
	$("#containerMatriceria").html(str);
	ret=setTable("matricerias",0);
		
	return ret;
}
function borrarMatriceria(idItem){
	confirmaBorra("Esta seguro de eliminar esta matriceria y todos sus componentes?","borraMat",idItem);
}

function borraMat(id){
	var params={};
	params["baja"]=1;	
	updateById("matriceria",params,id);
	armaTablaMatriceria();
	$.unblockUI();
}

function armaVista(id){
 	var x;
	var str="";
	var params={};
	params["idMatriceria"]=id;
	items=DBHload("matriceria_item",params,"idTipo");
	
	
	for (x=0;x<items.rowCount;x++){
		var obj=items.rows[x];		
		str += "<h3>" +  tipos[obj.idTipo] + " (" +  obj.codigo + ") | <span style='text-indent: 5em'>" + estados[obj.idEstado] + " </span> " +  "</h3>";
		if (obj.planoURL!=""){
			str+="<div><p><span style='display:block'><a href=\"file://///" + obj.planoURL + "\" target='_blank'> Ver Plano </a></span>";
		}else{
			str+="<div><p><span style='display:block'>Item sin Plano Adjunto</span>";
		}
		var params={};
		params["idItem"]=obj.id;
		cotas=DBHload("matriceria_item_cota",params,"nombre");
		str += "<table><thead><th>Cota</th><th>Minimo</th><th>Maximo</th></thead>";
		for (i=0;i<cotas.rowCount;i++){
			
			var cota=cotas.rows[i];
			str+= "<TR><TD>" + cota.nombre + "</TD><TD>" + cota.minimo + "</TD><TD>" + cota.maximo + "</TD></TR>";
		}
		str+="</table></p></div>";
	}
	$("#vista").html(str);			
	$( "#vista" ).accordion();
}

</script>
		<input type="hidden" id="idItemWork"/>
		<input type="hidden" id="idMatriceriaWork"/>
		<div id="dialogDiv"></div>
<?php 
	include "menuMatriceria.html";
	?>
	<div class="container_12">
		<div class="grid_10">
			<div class="box round first">
				<h2>Matriceria</h2>
				<div class="block">
					<div id="containerMatriceria"></div>
				</div>
			</div>
		</div>
	</div>
	<div id="dialogDiv"></div>
	<div id="popUp" style="display:none">
	<table style="width: 100%">
		<TR>
			<TD width="90%" style="background: black; color: white;">Detalle Matriceria</TD>
			<TD	style="background: black; color: white; border-left: 1px solid white">
				<a href="javascript:cerrarPopUp()"><img src="images/clear.jpg"	height="10px" /> </a>
			</TD>
		</TR>
	</table>
	<div id="vista"></div>
</div>
    <?php include "footer.html"?>